/** JTable:
    The application uses JTable object to display records in the database.
The JTable is based on model that is built upon JDBC 2.0 result set.
*/
// import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class JDBC2Table extends JApplet implements ActionListener {
   JTable tbl = null;
   JScrollPane scrollPane = null;
   JButton btnAdd = new JButton("Add"), btnSave = new JButton("Save");
   JLabel  lbFilter = new JLabel("Filtering ");
   JTextField strFilter = new JTextField(20);
   JPanel  pnButtons = new JPanel();
   Container c;

   JDBC2TableModel pTblMdl = new JDBC2TableModel();

   public JDBC2Table() { }

   public void init () {
	c = getContentPane();
	tbl = new JTable( pTblMdl );
	scrollPane = new JScrollPane(tbl); // No scrollpane, no column titles will be displayed.

	// Register listener with components.
	btnAdd.addActionListener(this);
	btnSave.addActionListener(this);
	strFilter.addActionListener(this);

	// Set tooltip with button.
	btnAdd.setToolTipText("Add new record");
	btnSave.setToolTipText("Save batch update");

	// Add buttons to panel.
	pnButtons.add(btnAdd); pnButtons.add(btnSave);

	pnButtons.add(lbFilter); pnButtons.add(strFilter);

	// Add pane to window.
	c.add(pnButtons, BorderLayout.SOUTH);
	c.add(scrollPane, BorderLayout.CENTER);
   }

   public void actionPerformed(ActionEvent e) {
	Object obj = e.getSource();
	if ( obj == strFilter ) {
		pTblMdl.requry( strFilter.getText().trim() );
	} else JOptionPane.showMessageDialog(null, "Not Done Yet", "Possible assignment.", JOptionPane.PLAIN_MESSAGE) ;
	return ;
   }

   public void paint(Graphics g) {
	super.paint(g);
   }

   public static void main(String args[]) {
	JFrame apObject = new JFrame();
	apObject.setTitle("JDBC 2.0, JTabl and Access to Oracle DB");	
	JApplet alObject = new JDBC2Table();
	alObject.init(); alObject.start();
	apObject.getContentPane().add(alObject);
	apObject.setSize(600, 400);
	apObject.setVisible(true);
	apObject.addWindowListener( new WindowAdapter() {
		public void windowClosing(WindowEvent e) {
			System.exit(0);
		}} );
   }
}

